﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Collections.Generic
Imports GenDotNet.Task.Common
Imports GenDotNet.ObjectModel
Imports GenDotNet.Model.Common

Public Class ForEachInfo

   Private mLoopDelegate As EmptyDelegate
   Private mLoopIn As String
   Private mLoopNetType As NetTypeInfo
   Private mLoopVariable As String

   'Public Sub New( _
   '         ByVal loopVariable As String, _
   '         ByVal loopIn As String, _
   '         ByVal loopDelegate As EmptyDelegate)
   '   Me.mLoopDelegate = loopDelegate
   '   Me.mLoopVariable = loopVariable
   '   Me.mLoopIn = loopIn
   'End Sub

   Public Sub New( _
            ByVal loopVariable As String, _
            ByVal loopIn As String, _
            ByVal loopNetType As NetTypeInfo, _
            ByVal loopDelegate As EmptyDelegate)
      Me.mLoopDelegate = loopDelegate
      Me.mLoopVariable = loopVariable
      Me.mLoopIn = loopIn
      Me.LoopNetType = loopNetType
   End Sub

   Public Property LoopVariable() As String
      Get
         Return mLoopVariable
      End Get
      Set(ByVal value As String)
         mLoopVariable = value
      End Set
   End Property

   Public Property LoopNetType() As NetTypeInfo
      Get
         Return mLoopNetType
      End Get
      Set(ByVal value As NetTypeInfo)
         mLoopNetType = value
      End Set
   End Property

   Public Property LoopIn() As String
      Get
         Return mLoopIn
      End Get
      Set(ByVal value As String)
         mLoopIn = value
      End Set
   End Property

   Public Property LoopDelegate() As EmptyDelegate
      Get
         Return mLoopDelegate
      End Get
      Set(ByVal value As EmptyDelegate)
         mLoopDelegate = value
      End Set
   End Property

End Class

Namespace VB
   Public Module ForEachInfoExtensions

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As ForEachInfo, ByVal context As IBaseData) As String
         Return _
<code>
      For Each <%= info.LoopVariable.WithSpace %>
   <%= If(info.LoopNetType Is Nothing, String.Empty, " As " & info.LoopNetType.Output) %> In <%= info.LoopIn %>
   <%= info.LoopDelegate.Invoke() %>
      Next
</code>.Value
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As ForEachInfo) As String
         Return info.Output(Nothing)
      End Function
   End Module
End Namespace

Namespace CSharp
   Public Module ForEachInfoExtensions
      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As ForEachInfo, ByVal context As IBaseData) As String
         Return _
<code>
      foreach (<%= If(info.LoopNetType Is Nothing, String.Empty, info.LoopNetType.Output.WithSpace) %>
   <%= info.LoopVariable %> in <%= info.LoopIn %>)
         {
   <%= info.LoopDelegate.Invoke() %>
         }
</code>.Value
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As ForEachInfo) As String
         Return info.Output(Nothing)
      End Function
   End Module
End Namespace